{{--/**
 * Created by PhpStrom
 * User: 郭碧云
 * Date: 2021/3/15 17:48
 * Desc:
 */--}}
{{--添加--}}
<form id="permission_create" style="margin-top: 15px;" class="layui-form" action="{{route('system.permission.store')}}">
    {{csrf_field()}}
    <div class="layui-form-item">
        <label class="layui-form-label">权限分组</label>
        <div class="layui-input-block">
            <select id="type" name="data[type]">
                {!! Code::getOptionsByCode('PERMISSION_GROUP',2) !!}
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">父权限</label>
        <div class="layui-input-block">
            <div id="parent_id" style="width: 60%"></div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">名称</label>
        <div class="layui-input-block">
            <input type="text" id="name" name="data[name]" autocomplete="off" placeholder="请输入路由名称" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">选择守卫</label>
        <div class="layui-input-block">
            <select id="type" name="data[guard_name]" lay-verify="required">
                {!! Code::getOptionsByCode('GUARD','','--请选择--') !!}
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">显示名称</label>
        <div class="layui-input-block">
            <input type="text" id="display_name" name="data[display_name]" autocomplete="off" placeholder="请输入权限显示名称"
                   class="layui-input">
        </div>
    </div>
</form>
<script>
    $(function () {
        $("#name").blur(function () {
            admin.send('{{route('system.permission.check')}}', 'GET', {
                'data': {
                    'name': $("#name").val(),
                    'type': $("#type").val()
                }
            },0);
        });
    })
</script>
<script src="{{asset('layui/modules/xm-select.js')}}"></script>
<script src="{{asset('js/tree/select.js')}}"></script>
<script>
    var idx = -1;
    layui.use(['xmSelect'], function () {
        var xmSelect = layui.xmSelect;

        let params=selectTreeParams('#parent_id','data[parent_id]','请选择',"",JSON.parse('{!! $permissions !!}'),function (data){
            $(".perPar").val(data.arr[0].id);
        });
        xmSelect.render(params)
    });
</script>
